function textFormat(val) {
	// 格式化文字展示文本域格式文字
	if (val) {
		let newString = val.replace(/\n/g, '_@').replace(/\r/g, '_#');
		newString = newString.replace(/_#_@/g, '<br/>'); // IE7-8
		newString = newString.replace(/_@/g, '<br/>'); // IE9、FF、chrome
		newString = newString.replace(/\s/g, '&nbsp;'); // 空格处理
		return newString;
	}
}
/**
 * 乘法
 * @param arg1
 * @param arg2
 * @returns {Number}
 */
function accMul(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try { m += s1.split(".")[1].length } catch (e) { }
    try { m += s2.split(".")[1].length } catch (e) { }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
/**
 * 除法
 * @param arg1
 * @param arg2
 * @returns {Number}
 */
function accDiv(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
    try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
    r1 = Number(arg1.toString().replace(".", ""))
    r2 = Number(arg2.toString().replace(".", ""))   
	return (r1 / r2) * Math.pow(10, t2 - t1);
}
/**
 * 加法
 * @param arg1
 * @param arg2
 * @returns {Number}
 */
function accAdd(arg1, arg2) {
    var r1, r2, m, c;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    c = Math.abs(r1 - r2);
    m = Math.pow(10, Math.max(r1, r2))
    if (c > 0) {
        var cm = Math.pow(10, c);
        if (r1 > r2) {
            arg1 = Number(arg1.toString().replace(".", ""));
            arg2 = Number(arg2.toString().replace(".", "")) * cm;
        }
        else {
            arg1 = Number(arg1.toString().replace(".", "")) * cm;
            arg2 = Number(arg2.toString().replace(".", ""));
        }
    }
    else {
        arg1 = Number(arg1.toString().replace(".", ""));
        arg2 = Number(arg2.toString().replace(".", ""));
    }
    return (arg1 + arg2) / m
}
/**
 * 减法
 * @param arg1
 * @param arg2
 * @returns
 */
function accSub(arg1,arg2){
	var r1,r2,m,n;
	try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
	try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
	m=Math.pow(10,Math.max(r1,r2));
	//last modify by deeka
	//动态控制精度长度
	n=(r1>=r2)?r1:r2;
	return ((arg1*m-arg2*m)/m).toFixed(n);
}

function add0(m){return m<10?'0'+m:m }
function format(e){
	var time = new Date(e);
	var y = time.getFullYear();
	var m = time.getMonth()+1;
	var d = time.getDate();
	return y+'-'+add0(m)+'-'+add0(d);
}


function convertHtmlToText(inputText) {
	var returnText = "" + inputText;
	returnText = returnText.replace(/<\/div>/ig, '\r\n');
	returnText = returnText.replace(/<\/li>/ig, '\r\n');
	returnText = returnText.replace(/<li>/ig, '  *  ');
	returnText = returnText.replace(/<\/ul>/ig, '\r\n');
	//-- remove BR tags and replace them with line break
	returnText = returnText.replace(/<br\s*[\/]?>/gi, "\r\n");

	//-- remove P and A tags but preserve what's inside of them
	returnText = returnText.replace(/<p.*?>/gi, "\r\n");
	returnText = returnText.replace(/<a.*href="(.*?)".*>(.*?)<\/a>/gi, " $2 ($1)");

	//-- remove all inside SCRIPT and STYLE tags
	returnText = returnText.replace(/<script.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/script>/gi, "");
	returnText = returnText.replace(/<style.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/style>/gi, "");
	//-- remove all else
	returnText = returnText.replace(/<(?:.|\s)*?>/g, "");

	//-- get rid of more than 2 multiple line breaks:
	returnText = returnText.replace(/(?:(?:\r\n|\r|\n)\s*){2,}/gim, "\r\n\r\n");

	//-- get rid of more than 2 spaces:
	returnText = returnText.replace(/ +(?= )/g, '');

	//-- get rid of html-encoded characters:
	returnText = returnText.replace(/&nbsp;/gi, " ");
	returnText = returnText.replace(/&amp;/gi, "&");
	returnText = returnText.replace(/&quot;/gi, '"');
	returnText = returnText.replace(/&lt;/gi, '<');
	returnText = returnText.replace(/&gt;/gi, '>');

	return returnText;
}

function getT(t) {
	let myDate = new Date(t);
	let year = myDate.getFullYear();
	let month = myDate.getMonth() + 1 < 10 ? '0' + (myDate.getMonth() + 1) : myDate.getMonth() + 1;
	let day = myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate();
	let hour = myDate.getHours() < 10 ? '0' + myDate.getHours() : myDate.getHours();
	let minute = myDate.getMinutes() < 10 ? '0' + myDate.getMinutes() : myDate.getMinutes();
	let second = myDate.getSeconds() < 10 ? '0' + myDate.getSeconds() : myDate.getSeconds();
	let this_time = year + '-' + month + '-' + day
	return this_time
}

export {
	textFormat,
	accMul,
	accDiv,
	accAdd,
	accSub,
	format,
	convertHtmlToText,
	getT
}